package com.pmcc.core.repository;

import com.pmcc.core.entity.security.Attachment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by zzy on 2018/3/19.
 * 附件表的接口
 */
public interface SystemAttachmentRepository extends JpaRepository<Attachment, String> {

    @Transactional(timeout = 10)
    @Modifying
    @Query(value = "UPDATE  sys_attachment SET BUSINESS_DATA_ID =?1 WHERE ID=?2", nativeQuery = true)
    Integer updateAttachmentById(String businessDataId, String id);


    @Transactional(timeout = 10)
    @Modifying
    @Query(value = "UPDATE  sys_attachment SET BUSINESS_DATA_ID =?1 WHERE ID IN ?2", nativeQuery = true)
    Integer updateAttachmentByIds(String businessDataId, List<String> ids);


    @Transactional(timeout = 10)
    @Modifying
    @Query(value = "UPDATE sys_attachment SET DEL_FLAG =?1 WHERE ID IN ?2", nativeQuery = true)
    Integer deleteByIds(String delFlag, List<String> ids);


    List<Attachment> findByBusinessDataIdAndDelFlag(String businessDataId, String delFlag);

    @Transactional(timeout = 10)
    @Modifying
    @Query(value = "UPDATE sys_attachment SET DEL_FLAG ='1' WHERE BUSINESS_DATA_ID = ?1", nativeQuery = true)
    Integer deleteByBusinessDataId(String businessDataId);
}
